const mongoose = require('mongoose');
async function main(){
    await mongoose.connect('mongodb://localhost:27017/local');
    let TextSchema = new mongoose.Schema({
        name:{
            type:String,
            age:Number,
        },
        book:{
            type:String,
        }
    })

    TextSchema.post('save',function(doc){
        console.log('save after run post',JSON.stringify(doc))
    })
    TextSchema.pre('save', function(next,doc){
        console.log('save pre run success', JSON.stringify(doc))
        next()
    })
    let FormModule = mongoose.model('forms',TextSchema)
    let sub = new FormModule({
        name:'submit form',
        book:'new book'
    })

    sub.save()

}
main()
